<?php

$a = !empty($_GET['a']) ? $_GET['a'] : 'list';
$blogApi = new blog();
echo json_encode($blogApi->$a(), JSON_UNESCAPED_UNICODE);


class blog
{

    public $data = [
        ['title' => '商城组每周的一个分享', 'content' => '一般人我不告诉他哦','image'=>'http://7sbrd6.com1.z0.glb.clouddn.com/552634d95796e.png'],
        ['title' => '回收不堪的往事', 'content' => '一般人我不告诉他哦','image'=>'http://qty83k.creatby.com/materials/origin/c5656ef00d38d89eae437c5a9102f8fa_origin.png'],
        ['title' => 'centos7的docker镜像的坑', 'content' => '一般人我不告诉他哦','image'=>'http://7sbrd6.com1.z0.glb.clouddn.com/54a8fcea54697.jpg'],
        ['title' => '那些年追过的女孩', 'content' => '一般人我不告诉他哦','image'=>'http://7sbrd6.com1.z0.glb.clouddn.com/54a236d8360a6.jpg'],
        ['title' => '我一定会回来的', 'content' => '一般人我不告诉他哦','image'=>'http://7sbrd6.com1.z0.glb.clouddn.com/549304a8be63d.jpg'],
        ['title' => '别看我只是一只羊', 'content' => '一般人我不告诉他哦','image'=>'http://7sbrd6.com1.z0.glb.clouddn.com/5491a32820abc.jpg'],
    ];

    /**
     * 获取数据列表
     * @return array
     * @author soupqingsong@foxmail.com
     */
    public function list()
    {
        $data = $this->data;

        foreach ($data as &$val) {
            $val = $this->formatData($val);
        }
        return $data;
    }

    /**
     * 获取详情页
     * @param $id
     * @return mixed
     * @author soupqingsong@foxmail.com
     */
    public function detail()
    {
        $id = $_GET['id'] ?? 1;
        return $this->formatData($this->data[$id - 1]);
    }

    public function formatData($data)
    {
        $data['date'] = date('Y-m-d', time() - rand(100000, 1000000));
        $data['view'] = rand(0, 1000);

        return $data;
    }

}
